package com.example.demo.controller;


import com.example.demo.ResBean.constant.ResCode;
import com.example.demo.entity.response.Response;
import com.example.demo.entity.sqlbean.Repair;
import com.example.demo.service.RepairService;
import com.example.demo.utils.JsonUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
//@Api(tags ="维修接口")
@RestController
@RequestMapping("/Repair")
@CrossOrigin(origins = "*", maxAge = 3600)
public class RepairController {

    @Autowired
    RepairService repairService;


    @RequestMapping("new")
    public Response saveRepair(@RequestParam String data) {
        Response response = new Response();
        Repair repair = JsonUtil.getInstance().jsonToBean(data , Repair.class);
        if (repair != null){
            response = repairService.insertRepair(repair);
        }
        else
        {
            response.setCode(ResCode.Param_ilegal_code);
            response.setMessage(ResCode.Param_ilegal_str);
        }
        return response;
    }

    @RequestMapping("data")
    public Response selectRepair(@RequestParam String data){
        Long approvalId = Long.parseLong(JsonUtil.jsonToMap(data).get("id"));
        return repairService.selectRepair(approvalId);
    }

    @RequestMapping("courier")
    public Response selectCourier(@RequestParam String data){
        Long approvalId = Long.parseLong(JsonUtil.jsonToMap(data).get("id"));
        return repairService.selectRepairExpressNo(approvalId);
    }

}
